
package com.flinkBigWork.util;


import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.functions.windowing.AllWindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;
import redis.clients.jedis.Jedis;

import java.util.*;


public class OneSecondRes1 implements AllWindowFunction<Tuple2<Integer, String>, String, TimeWindow> {
    @Override
    public void apply(TimeWindow timeWindow, Iterable<Tuple2<Integer, String>> input, Collector<String> out) {


        if (!input.iterator().hasNext()) {
            return;
        }
        Tuple2<Integer, String> result = input.iterator().next();
        Integer counts = result.f0;
        String time = result.f1;
//        System.out.println(time);
        String listKey = "issue1";


        try (Jedis jedis = jedisPool.getJedis()) {
            if (jedis != null) {
                // 切换到数据库1号
                jedisPool.select_db0(jedis);
                jedis.rpush(listKey, time);
                jedis.rpush(listKey, String.valueOf(counts));
                }
            else{
                    System.out.println("Jedis is not initialized.");
                }
            } catch(Exception e){
                e.printStackTrace();
            }
        }




}
